home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / src / mail / pine3.96.tar.gz / pine3.96.tar / pine3.96 / imap / ANSI / c-client / nl_mac.c < prev    next >
C/C++ Source or Header  |  1994-10-09  |  3KB  |  78 lines

  1. /*
  2.  * Program:    Mac newline routines
  3.  *
  4.  * Author:    Mark Crispin
  5.  *        6158 Lariat Loop NE
  6.  *        Bainbridge Island, WA  98110-2098
  7.  *        Internet: MRC@Panda.COM
  8.  *
  9.  * Date:    26 January 1992
  10.  * Last Edited:    9 October 1994
  11.  *
  12.  * Copyright 1994 by Mark Crispin
  13.  *
  14.  *  Permission to use, copy, modify, and distribute this software and its
  15.  * documentation for any purpose and without fee is hereby granted, provided
  16.  * that the above copyright notice appears in all copies and that both the
  17.  * above copyright notices and this permission notice appear in supporting
  18.  * documentation, and that the name of Mark Crispin not be used in advertising
  19.  * or publicity pertaining to distribution of the software without specific,
  20.  * written prior permission.  This software is made available "as is", and
  21.  * MARK CRISPIN DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, WITH REGARD TO
  22.  * THIS SOFTWARE, INCLUDING WITHOUT LIMITATION ALL IMPLIED WARRANTIES OF
  23.  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, AND IN NO EVENT SHALL
  24.  * MARK CRISPIN BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES
  25.  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  26.  * WHETHER IN AN ACTION OF CONTRACT, TORT (INCLUDING NEGLIGENCE) OR STRICT
  27.  * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
  28.  * THIS SOFTWARE.
  29.  *
  30.  */
  31.  
  32. /* Copy string with CRLF newlines
  33.  * Accepts: destination string
  34.  *        pointer to size of destination string buffer
  35.  *        source string
  36.  *        length of source string
  37.  * Returns: length of copied string
  38.  */
  39.  
  40. unsigned long strcrlfcpy (char **dst,unsigned long *dstl,char *src,
  41.               unsigned long srcl)
  42. {
  43.   long i,j;
  44.   char *d = src;
  45.                 /* count number of CR's in source string(s) */
  46.   for (i = srcl,j = 0; j < srcl; j++) if (*d++ == '\015') i++;
  47.                 /* flush destination buffer if too small */
  48.   if (*dst && (i > *dstl)) fs_give ((void **) dst);
  49.   if (!*dst) {            /* make a new buffer if needed */
  50.     *dst = (char *) fs_get ((*dstl = i) + 1);
  51.     if (dstl) *dstl = i;    /* return new buffer length to main program */
  52.   }
  53.   d = *dst;            /* destination string */
  54.   while (srcl--) {        /* copy strings */
  55.     *d++ = *src++;        /* copy character */
  56.                 /* append line feed to bare CR */
  57.     if ((*src == '\015') && (src[1] != '\012')) *d++ = '\012';
  58.   }
  59.   *d = '\0';            /* tie off destination */
  60.   return d - *dst;        /* return length */
  61. }
  62.  
  63.  
  64. /* Length of string after strcrlfcpy applied
  65.  * Accepts: source string
  66.  * Returns: length of string
  67.  */
  68.  
  69. unsigned long strcrlflen (STRING *s)
  70. {
  71.   unsigned long pos = GETPOS (s);
  72.   unsigned long i = SIZE (s);
  73.   unsigned long j = i;
  74.   while (j--) if ((SNX (s) == '\015') && ((CHR (s) != '\012') || !j)) i++;
  75.   SETPOS (s,pos);        /* restore old position */
  76.   return i;
  77. }
  78.